package stu.cms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import stu.cms.pojo.dto.UserDTO;
import stu.cms.pojo.entity.Dept;
import stu.cms.pojo.entity.User;
import stu.cms.result.PageResult;
import stu.cms.result.Result;
import stu.cms.service.DeptService;

import java.util.List;
@Api(tags ="部门管理")
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    DeptService deptService;

    @ApiOperation("查询部门")
    @GetMapping("/list")
    public Result<List<Dept>> getAllUser() {
        List<Dept> depts = deptService.list();
        return Result.success(depts);
    }

    @ApiOperation("添加或者修改部门")
    @PostMapping("/save")
    public Result save(@RequestBody Dept dept) {
        deptService.saveDept(dept);
        return Result.success();
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        deptService.removeDept(id);
        return Result.success();
    }

}
